<template>
  <div class="main">
    <el-tabs v-model="activeName" @tab-click="msgtabChange" class="tabs-content">
      <el-tab-pane label="系统通知" name="1">
        <div class="tabs-item" v-for="item in msgList" :key="item.messageId">
          <div class="tabs-message" >
            <div class="tabs-msg" >
              <p class="msg-time">{{item.sendTime}}</p>
              <p class="msg-contain">{{item.messageContent}}</p>
            </div>
          </div>
          <div class="msg-border"></div>
        </div>
        <v-pagination v-if="total" :pg="page" :size="pageSize" :total="total" @page-change="pageChange"></v-pagination>
        <!-- <div class="tabs-msg-no" v-if="msgList.length === 0">
            暂无消息
        </div> -->
      </el-tab-pane>
      <el-tab-pane label="物流助手" name="8">
        <div class="tabs-wl" v-for="item in msgList" :key="item.messageId">
          <div class="wl-time">{{item.sendTime}}</div>
          <div class="wl-img">
            <img :src='item.bannerImage' width="100%"/>
          </div>
          <div class="wl-right">
            <p>您的订单已发货{{item.messageContent}}，请注意查收</p>
            <p @click="goOrder(item.messageContent)">查看详情</p>
          </div>
        </div>
        <v-pagination v-if="total" :pg="page" :size="pageSize" :total="total" @page-change="pageChange"></v-pagination>
        <!-- <div class="tabs-msg-no" v-if="msgList.length === 0">
            暂无消息
        </div> -->
      </el-tab-pane>
      <el-tab-pane label="活动促销" name="5">
        <div class="tabs-wl" v-for="item in msgList" :key="item.messageId">
          <div class="wl-time">{{item.sendTime}}</div>
          <div class="wl-img">
            <img :src='item.bannerImage' width="100%" height="100%"/>
          </div>
          <div class="wl-right">
            <p>{{item.messageTitle}}</p>
            <p @click="goActivity(item.messageContent)">查看详情</p>
          </div>
        </div>
        <v-pagination v-if="total" :pg="page" :size="pageSize" :total="total" @page-change="pageChange"></v-pagination>
        <!-- <div class="tabs-msg-no" v-if="msgList.length === 0">
            暂无消息
        </div> -->
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import vPagination from '@/components/public/pagination'
export default {
  data () {
    return {
      activeName: '1',
      msgStatus: '', // (1-系统通知 8-物流消息 5-活动通知)
      msgList: [],
      page: 1,
      pageSize: 10,
      total: 0
    }
  },
  components: {
    vPagination
  },
  mounted () {
    this.getData()
  },
  methods: {
    getData () {
      this.msgStatus = '1'
      this.getMessage()
    },
    msgtabChange (tab) {
      this.msgStatus = tab.name
      this.getMessage()
    },
    getMessage () {
      this.msgList = []
      this.$http.post(this.$api + '/pc/message/list', {
        page: this.page,
        pageSize: this.pageSize,
        type: this.msgStatus
      }).then(res => {
        if (res.responseCode === '0000') {
          this.msgList = res.data.list
          this.total = res.data.total
        }
      }).catch(() => {
        this.$message.error({
          message: '请求超时！'
        })
      })
    },
    // 切换页面
    pageChange (pg) {
      this.page = pg
      this.getMessage()
    },
    // 跳转至物流详情页
    goOrder (orderId) {
      this.$router.push('/order/logistics?orderId=' + orderId)
    },
    // 跳转至活动页面
    goActivity (activeId) {
      this.$router.push('/activity?activeId=' + activeId)
    }
  }
}
</script>

<style lang="scss">
@import '@/assets/scss/basic.scss';
.tabs-content {
  .el-tabs__header{
    margin-bottom: 25px;
    .el-tabs__item{
      font-size: $fz_16;
      font-weight: bold;
    }
  }
}
.el-tabs__nav-wrap::after {
  height: 3px;
}
.el-tabs__item{
  color: $f_main;
}
.el-tabs__active-bar{
  height: 4px;
  bottom: 2px;
}
.tabs-message {
  width: 940px;
  background: #fff;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  position: relative;
  .tabs-msg{
    width: 940px;
    padding: 20px 40px 20px 30px;
    color: $f_main;
    .msg-time{
      font-size: $fz_14;
      padding-bottom: 6px;
      border-bottom: 1px solid $border_color;
    }
    .msg-contain{
      font-size: $fz_16;
      padding: 10px 0 0;
    }
  }
  .tabs-cards-no{
    width: 100%;
    text-align: center;
  }
}
.msg-border{
  width: 100%;
  height: 1px;
  background: $border_color;
  margin-bottom: 20px;
}
.tabs-item:last-of-type .msg-border {
  background: transparent
}
.tabs-wl{
  background: #fff;
  width: 1060px;
  padding: 10px 0 10px 30px;
  border: 1px solid $border_color;
  display: flex;
  font-size:  $fz_14;
  margin-bottom: 10px;
  .wl-time{
    line-height: 100px;
  }
  .wl-img{
    border: 1px solid $border_color;
    margin: 0 30px;
    width: 100px;
    height: 100px;
  }
  .wl-right{
    p:first-child{
      margin: 20px 0 12px 0;
    }
    p:last-child{
      text-decoration: underline;
      color: #fe2200;
      cursor: pointer;
    }
  }
}
.tabs-msg-no{
    background: #fff;
    padding: 20px 30px;
    text-align: center;
  }
</style>
